package com.highspeed.bdk.controller.physical;

import com.bianmaba.spring.data.jpa.domain.PageableRequest;
import com.bianmaba.spring.data.jpa.domain.PageableResult;
import com.bianmaba.spring.data.jpa.domain.Result;
import com.bianmaba.spring.mvc.method.support.annotations.EntityParam;
import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import com.bianmaba.spring.mvc.method.support.annotations.MapParam;
import com.highspeed.bdk.bean.entity.physical.LinkFoldPoint;
import com.highspeed.bdk.bean.entity.physical.PhysicalLink;
import com.highspeed.bdk.controller.base.BdkCrudController;
import com.highspeed.bdk.service.base.IBdkBaseService;
import com.highspeed.bdk.service.physical.ILinkFoldPointService;
import com.highspeed.bdk.service.physical.IPhysicalLinkService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;

@RestController
@RequestMapping(value = {"link_fold_point"}, method = RequestMethod.POST)
@Api(tags = "物理链路折点")
public class LinkFoldPointController extends BdkCrudController<LinkFoldPoint, Integer> {

    @Autowired()
    private ILinkFoldPointService service;

    @Override
    protected ILinkFoldPointService getService() {
        return this.service;
    }

    @ApiOperation(value = "保存物理链路折点", notes = "参数为JSON数据;<br/>" +
            "链路折点中中中必须包含：physicalLink.id<br/>")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @JSON(excludeProperties = {"data.*\\.physicalTopology", "data.*\\.leftCpu", "data.*\\.rightCpu", "data.*\\.foldPoints"})
    @Override
    public Result save(@RequestBody @ApiParam(name = "entity") LinkFoldPoint entity) {
        return super.save(entity);
    }

    @ApiOperation(value = "保存物理链路折点列表", notes = "参数为JSON数据;<br/>" +
            "每一个链路折点中中中必须包含;<br/>")
    @RequestMapping(value = "/saves", method = RequestMethod.POST)
    @JSON(excludeProperties = {"data.*\\.physicalTopology", "data.*\\.leftCpu", "data.*\\.rightCpu", "data.*\\.foldPoints"})
    @Override
    public Result save(@RequestBody @ApiParam(name = "entity") List<LinkFoldPoint> entity) {
        return super.save(entity);
    }


    @Override
    @JSON(excludeProperties = {"data.*\\.physicalTopology", "data.*\\.leftCpu", "data.*\\.rightCpu", "data.*\\.foldPoints"})
    public PageableResult query(@MapParam LinkedHashMap<String, Object> params, @EntityParam PageableRequest pageable) {
        return super.query(params, pageable);
    }

    @JSON
    @ApiOperation(value = "删除指定物理链路的折点列表")
    @ApiImplicitParam(name = "linkId", value = "0", dataType = "int", paramType = "query")
    @RequestMapping(value = "/delete_by_link_id", method = RequestMethod.POST)
    public Result deleteByLinkId(Integer linkId) {
        service.deleteByLinkId(linkId);
        return new Result(true);
    }
}
